package site.qjdb.pojo.pagination;

import site.qjdb.util.CommonUtils;

import java.util.HashMap;
import java.util.List;

/**
 * 	分页
 * 
 */
public class PageMap<T> {
	private T bean; // 查询条件
	private String orderBy; // 排序
	private PageBean pageBean; // 分页条件
	private List<Object> rangeList; // 范围

	public PageMap() {
	}
	public PageMap(T bean, String orderBy, PageBean pageBean, List<Object> rangeList) {
		this.bean = bean;
		this.orderBy = orderBy;
		this.pageBean = pageBean;
		this.rangeList = rangeList;
	}

	public PageMap(T bean, String orderBy, PageBean pageBean) {
		this.bean = bean;
		this.orderBy = orderBy;
		this.pageBean = pageBean;
	}

	public PageMap(String orderBy, PageBean pageBean) {
		this.orderBy = orderBy;
		this.pageBean = pageBean;
	}

	public PageMap(T bean, PageBean pageBean) {
		this.bean = bean;
		this.pageBean = pageBean;
	}

	public PageMap(T bean, String orderBy) {
		this.bean = bean;
		this.orderBy = orderBy;
	}

	public PageMap(T bean) {
		this.bean = bean;
	}

	public PageMap(String orderBy) {
		this.orderBy = orderBy;
	}

	public PageMap(PageBean pageBean) {
		this.pageBean = pageBean;
	}

	public HashMap<String, Object> get() {
		HashMap<String, Object> map = new HashMap<>();
		if (bean != null) {
			String name = bean.getClass().getSimpleName();
			name = String.valueOf(name.charAt(0)).toLowerCase() + name.substring(1);
			map.put(name, bean);
		}
		if(!CommonUtils.isEmpty(orderBy, true)) {
			map.put("orderBy", orderBy);
		}
		map.put("pageBean", pageBean);
		if(rangeList != null && rangeList.size() > 0) {
			map.put("rangeList", rangeList);
		}
		return map;
	}
}
